* Bootstrap procedure over entire causal link:
capture program drop layersbootstrap
program define layersbootstrap, rclass

	preserve
	bsample , cluster(firmcode) idcluster(newfirmcode)
	
	sort newfirmcode t
	xtset newfirmcode t

	* First stage identical for all cases:
	xtreg logsales I_WID I_transport_f2 yeardummy* sectordummy* if sample == 1, fe
	cap drop logsalespred
	predict logsalespred, xbu
	
	* GMM, ma(1) errors, one-step
	xtabond2 layers L.layers logsalespred sectordummy1-sectordummy8 yeardummy4-yeardummy12 if sample == 1, ///
	gmmstyle(L.layers, lag(3 .)) gmmstyle(logsalespred, lag(4 .)) robust
	return scalar layers_iv = _b[L.layers]
	return scalar sales_iv = _b[logsalespred]
	cap drop layers_iv_all
	predict layers_iv_all
	
	areg log2inequality1 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality1_iv = _b[layers_iv_all]
	areg log2inequality2 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality2_iv = _b[layers_iv_all]
	areg log2inequality4 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality4_iv = _b[layers_iv_all]
	areg log2inequality5 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality5_iv = _b[layers_iv_all]
	areg wagegap1_topbottom_log layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_log_iv = _b[layers_iv_all]
	
	areg res2inequality1_model2 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_iv = _b[layers_iv_all]
	areg res2inequality2_model2 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_iv = _b[layers_iv_all]
	areg res2inequality4_model2 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_iv = _b[layers_iv_all]
	areg res2inequality5_model2 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_iv = _b[layers_iv_all]
	areg wagegap1_topbottom_res2 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res2_iv = _b[layers_iv_all]
	
	areg res2inequality1_model4 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_iv_v2 = _b[layers_iv_all]
	areg res2inequality2_model4 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_iv_v2 = _b[layers_iv_all]
	areg res2inequality4_model4 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_iv_v2 = _b[layers_iv_all]
	areg res2inequality5_model4 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_iv_v2 = _b[layers_iv_all]
	areg wagegap1_topbottom_res4 layers_iv_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res4_iv_v2 = _b[layers_iv_all]
	
	restore
end
